package com.pwt.controller.crustallus;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.entity.AbilityLine;
import com.pwt.entity.Hierarchy;
import com.pwt.model.AbilityLineModel;
import com.pwt.model.TreeModel;
import com.pwt.service.AbilityLineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/10/8
 */
@RestController
@Tag(name = "筛选机床")
public class AbilityLineController {

    private AbilityLineService abilityLineService;

    public AbilityLineController(AbilityLineService abilityLineService) {
        this.abilityLineService = abilityLineService;
    }

    @GetMapping("/abilities")
    @Operation(description = "获取能力配置列表",summary = "获取能力配置列表")
    public List<AbilityLine> getList(){
        return this.abilityLineService.getList();
    }

    @PostMapping("/ability")
    @Operation(description = "新增",summary = "新增")
    public AbilityLine addAbility(@RequestBody AbilityLine abilityLineModel) throws CustomException {
        return this.abilityLineService.update(abilityLineModel);
    }

    @GetMapping("/ability")
    @Operation(description = "根据产线id查询产线名称和已选工序和机器",summary = "根据产线id查询产线名称和已选工序和机器")
    public AbilityLineModel getById(@Parameter(name = "id",description = "产线列表id") String id) throws CustomException {
        return this.abilityLineService.getById(id);
    }

    @PutMapping("/ability")
    @Operation(description = "编辑",summary = "编辑")
    public AbilityLine updateAbility(@RequestBody @Validated(Update.class) AbilityLine abilityLineModel) throws CustomException {
        return this.abilityLineService.update(abilityLineModel);
    }


    @GetMapping("/hierarchy-all")
    @Operation(description = "根据用户获取所有授权的工序和机器数据",summary = "根据用户获取所有授权的工序和机器数据")
    public List<TreeModel> getHierarchySelect(){
        return this.abilityLineService.getHierarchySelect();
    }

    @DeleteMapping("/ability/{id}")
    @Operation(description = "删除接口",summary = "删除接口")
    public void deleteAbility(@Parameter(description = "生产线ID") @PathVariable(name = "id") String id) throws CustomException {
        this.abilityLineService.deleteAbility(id);
    }


    @GetMapping("ability/treeList")
    @Operation(description = "获取机器树形结构",summary = "获取机器树形结构")
    public List<Hierarchy> getHierarchyALL(){
        return this.abilityLineService.queryAllHierarchy();
    }


    @GetMapping("ability/abilityLineId")
    @Operation(description = "根据产线id查询",summary = "根据产线id查询")
    public List<Hierarchy> getHierarchyByWhatLineId(String abilityLineId){
        return this.abilityLineService.queryHierarchyByAbilityLineId(abilityLineId);
    }
}
